package com.hele.sts.action.admin;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.hele.sts.dao.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hele.sts.webwork.PageAction;
import com.opensymphony.xwork2.ActionContext;
import org.springframework.beans.factory.annotation.Autowired;

public class LogManagerAction extends PageAction {
	static Logger logger = LoggerFactory.getLogger(LogManagerAction.class);
	public static final String DELETE = "delete";
	public static final String QUERY = "query";
	public static final String LIST = "list";
	String action;
	String userId;
	String userNameEk;
	String yhlx;
	String userName;
	String zch;
	String qymc;
	String yhsf;
	List qLogList;
	QLog qLogBean;
	String logId;
	String errorInfo;
	Date start;
	Date end;
	String paixu;
	int logcnt;
	int dyfscnt;
	List dyLogList;
	String djid;
	String nbxh;
	String realName;
	String firstFlag;
	String cxmd;
	String bz;

	@Autowired
	private XtLogDao xtLogDao;

	@Override
    public String execute() throws Exception {
		ActionContext ctx = ActionContext.getContext();
		Map session = ctx.getSession();
		String loginName = (String) session.get("AdminUser.loginName");
		if ((loginName == null) || (loginName.length() < 1)) {
			setErrorInfo("没有登录或登录超时！");
			return "error";
		}
		logger.debug(this.action);
		if(action==null){
			return "list";
		}
		if (("list".equalsIgnoreCase(this.action)) ) {
			return super.execute();
		}
		if ("dylist".equalsIgnoreCase(this.action)) {
			return dylist();
		}
		if ("delete".equalsIgnoreCase(this.action)) {
			return delete();
		}
		if ("query".equalsIgnoreCase(this.action)) {
			return query();
		}
		return null;
	}

	@Override
    public String getHref() {
		String href = "";
		if ((this.userId != null) && (this.userId.length() > 0)) {
			href = href + "&userId=" + this.userId;
		}
		if ((this.userNameEk != null) && (this.userNameEk.length() > 0)) {
			href = href + "&userNameEk=" + this.userNameEk;
		}
		if ((this.yhlx != null) && (this.yhlx.length() > 0)) {
			href = href + "&yhlx=" + this.yhlx;
		}
		if ((this.userName != null) && (this.userName.length() > 0)) {
			href = href + "&userName=" + this.userName;
		}
		if ((this.zch != null) && (this.zch.length() > 0)) {
			href = href + "&zch=" + this.zch;
		}
		if ((this.qymc != null) && (this.qymc.length() > 0)) {
			href = href + "&qymc=" + this.qymc;
		}
		if (this.start != null) {
			href = href + "&start=" + this.start;
		}
		if (this.end != null) {
			href = href + "&end=" + this.end;
		}
		return href;
	}

	@Override
    public int count() {
		ActionContext ctx = ActionContext.getContext();
		Map session = ctx.getSession();
		String djjg = (String) session.get("AdminUser.djjg");
		return QLogDao.count(this.userId, this.userNameEk, this.yhlx, this.userName, this.zch, this.qymc, this.yhsf,
				this.start, this.end, djjg,this.realName,this.cxmd,this.bz);
	}

	public int dyfscount() {
		ActionContext ctx = ActionContext.getContext();
		Map session = ctx.getSession();
		String djjg = (String) session.get("AdminUser.djjg");
		return QLogDao.dyfscount(this.userId, this.userNameEk, this.yhlx, this.userName, this.zch, this.qymc,
				this.yhsf, this.start, this.end, djjg,this.realName,this.cxmd);
	}

	@Override
    public String list() {
		if ((this.paixu == null) || ("".equals(this.paixu))) {
			this.paixu = "cxrq";
		}
		if(firstFlag!=null){
			this.dyfscnt = dyfscount();
			ActionContext ctx = ActionContext.getContext();
			Map session = ctx.getSession();
			String djjg = (String) session.get("AdminUser.djjg");
			this.qLogList = QLogDao.load(this.userId, this.userNameEk, this.yhlx, this.userName, this.zch, this.qymc,
					this.yhsf, this.start, this.end, getPageNo(), getPageSize(), this.paixu, djjg,this.realName,this.cxmd,this.bz);

		}
        ActionContext ctx = ActionContext.getContext();
        Map session = ctx.getSession();
        User adminUser = (User)session.get(("AdminUser"));
        xtLogDao.insertLog("业务日志","后管日志查询成功",adminUser.getUserId(),adminUser.getUserName(),"成功","用户："+adminUser.getUserId(),this.getClass().getName());

        return "list";
	}

	public String dylist() {
		Qyhznr qyhznr = QyhznrDao.load(this.nbxh);
		this.qymc = qyhznr.getQymc();
		this.zch = qyhznr.getZch();
		this.dyLogList = QLogDao.loadDyLogList(this.djid,this.nbxh,this.start,this.end);
		return "dylist";
	}

	public String getPaixu() {
		return this.paixu;
	}

	public void setPaixu(String paixu) {
		this.paixu = paixu;
	}

	public String delete() {
		return "delete";
	}

	public String query() {
		this.qLogBean = QLogDao.load(this.logId);
		return "query";
	}

	public String getAction() {
		return this.action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getUserId() {
		return this.userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserNameEk() {
		return this.userNameEk;
	}

	public void setUserNameEk(String userNameEk) {
		this.userNameEk = userNameEk;
	}

	public String getYhlx() {
		return this.yhlx;
	}

	public void setYhlx(String yhlx) {
		this.yhlx = yhlx;
	}

	public String getUserName() {
		return this.userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getZch() {
		return this.zch;
	}

	public void setZch(String zch) {
		this.zch = zch;
	}

	public String getQymc() {
		return this.qymc;
	}

	public void setQymc(String qymc) {
		this.qymc = qymc;
	}

	public List getQLogList() {
		return this.qLogList;
	}

	public void setQLogList(List qLogList) {
		this.qLogList = qLogList;
	}

	public QLog getQLogBean() {
		return this.qLogBean;
	}

	public void setQLogBean(QLog qLogBean) {
		this.qLogBean = qLogBean;
	}

	public String getErrorInfo() {
		return this.errorInfo;
	}

	public void setErrorInfo(String errorInfo) {
		this.errorInfo = errorInfo;
	}

	public Date getStart() {
		return this.start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public Date getEnd() {
		return this.end;
	}

	public void setEnd(Date end) {
		this.end = end;
	}

	public int getLogcnt() {
		return this.logcnt;
	}

	public void setLogcnt(int logcnt) {
		this.logcnt = logcnt;
	}

	public String getYhsf() {
		return this.yhsf;
	}

	public void setYhsf(String yhsf) {
		this.yhsf = yhsf;
	}

	public int getDyfscnt() {
		return this.dyfscnt;
	}

	public void setDyfscnt(int dyfscnt) {
		this.dyfscnt = dyfscnt;
	}

	/**
	 * @return the dyLogList
	 */
	public List getDyLogList() {
		return dyLogList;
	}

	/**
	 * @param dyLogList
	 *            the dyLogList to set
	 */
	public void setDyLogList(List dyLogList) {
		this.dyLogList = dyLogList;
	}

	/**
	 * @return the djid
	 */
	public String getDjid() {
		return djid;
	}

	/**
	 * @param djid
	 *            the djid to set
	 */
	public void setDjid(String djid) {
		this.djid = djid;
	}

	/**
	 * @return the nbxh
	 */
	public String getNbxh() {
		return nbxh;
	}

	/**
	 * @param nbxh the nbxh to set
	 */
	public void setNbxh(String nbxh) {
		this.nbxh = nbxh;
	}

	/**
	 * @return the realName
	 */
	public String getRealName() {
		return realName;
	}

	/**
	 * @param realName the realName to set
	 */
	public void setRealName(String realName) {
		this.realName = realName;
	}

	/**
	 * @return the firstFlag
	 */
	public String getFirstFlag() {
		return firstFlag;
	}

	/**
	 * @param firstFlag the firstFlag to set
	 */
	public void setFirstFlag(String firstFlag) {
		this.firstFlag = firstFlag;
	}

	/**
	 * @return the cxmd
	 */
	public String getCxmd() {
		return cxmd;
	}

	/**
	 * @param cxmd the cxmd to set
	 */
	public void setCxmd(String cxmd) {
		this.cxmd = cxmd;
	}

	/**
	 * @return the bz
	 */
	public String getBz() {
		return bz;
	}

	/**
	 * @param bz the bz to set
	 */
	public void setBz(String bz) {
		this.bz = bz;
	}

	
}
